/*
 * @Author: 晟松
 * @Date: 2021-12-10 15:55:39
 * @LastEditors: 晟松
 * @LastEditTime: 2021-12-10 15:59:20
 * @FilePath: \mini-vue3d:\Code\node\koa2\volunteer-service\src\main\util\JwtUtils.js
 * @Description: jwt的加解密
 */

import jwt from "jsonwebtoken";
import config from "@main/config";

export const encrypt = (payload) => {
    return jwt.sign(payload, config.jwt.secret, {
        expiresIn: config.jwt.expiresIn,
    });
};

export const decrypt = (token) => {
    try {
        let data = jwt.verify(token, secret);
        return {
            token: true,
            data,
        };
    } catch (e) {
        return {
            token: false,
            data: e,
        };
    }
};
